package com.ruoyi.project.dict.checkzi.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.checkzi.domain.CheckZi;
import com.ruoyi.project.dict.checkzi.service.ICheckZiService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 测字列表Controller
 * 
 * @author shixiangwen
 * @date 2024-10-31
 */
@Controller
@RequestMapping("/dict/checkzi")
public class CheckZiController extends BaseController
{
    private String prefix = "dict/checkzi";

    @Autowired
    private ICheckZiService checkZiService;

    @RequiresPermissions("dict:checkzi:view")
    @GetMapping()
    public String checkzi()
    {
        return prefix + "/checkzi";
    }

    /**
     * 查询测字列表列表
     */
    @RequiresPermissions("dict:checkzi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CheckZi checkZi)
    {
        startPage();
        List<CheckZi> list = checkZiService.selectCheckZiList(checkZi);
        return getDataTable(list);
    }

    /**
     * 导出测字列表列表
     */
    @RequiresPermissions("dict:checkzi:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CheckZi checkZi)
    {
        List<CheckZi> list = checkZiService.selectCheckZiList(checkZi);
        ExcelUtil<CheckZi> util = new ExcelUtil<CheckZi>(CheckZi.class);
        return util.exportExcel(list, "checkzi");
    }

    /**
     * 新增测字列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存测字列表
     */
    @RequiresPermissions("dict:checkzi:add")
    @Log(title = "测字列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CheckZi checkZi)
    {
        return toAjax(checkZiService.insertCheckZi(checkZi));
    }

    /**
     * 修改测字列表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CheckZi checkZi = checkZiService.selectCheckZiById(id);
        mmap.put("checkZi", checkZi);
        return prefix + "/edit";
    }

    /**
     * 修改保存测字列表
     */
    @RequiresPermissions("dict:checkzi:edit")
    @Log(title = "测字列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CheckZi checkZi)
    {
        return toAjax(checkZiService.updateCheckZi(checkZi));
    }

    /**
     * 删除测字列表
     */
    @RequiresPermissions("dict:checkzi:remove")
    @Log(title = "测字列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(checkZiService.deleteCheckZiByIds(ids));
    }
}
